* Implemented the Exif::version() check, if the version in the stored metadata
does not match the current version the exif data is regenerated and the
current version saved in the metadata. Ensured that old images are updated
in the future if the output format is changed.
$db->freeResult( $res );
return $retVal;
}
$db->freeResult( $res );
return $retVal;
}
+ /**
+ * Retrive Exif data from the database
+ *
+ * Retrive Exif data from the database and prune unrecognized tags
+ * and/or tags with invalid contents
+ *
+ * @return array
+ */
function retrieveExifData () {
global $wgShowEXIF ;
if ( ! $wgShowEXIF ) return array ();
function retrieveExifData () {
global $wgShowEXIF ;
if ( ! $wgShowEXIF ) return array ();
foreach($exif as $k => $v) {
if ( !in_array($k, $this->exif->mValidExif) ) {
foreach($exif as $k => $v) {
if ( !in_array($k, $this->exif->mValidExif) ) {
- wfDebug( "Image::retrieveExifData: '$k' was not a valid Exif tag (contents: '$v')\n");
+ wfDebug( "Image::retrieveExifData: '$k' is not a valid Exif tag (type: '" . gettype($v) . "'; data: '$v')\n");
unset($exif[$k]);
}
}
foreach($exif as $k => $v) {
if ( !$this->exif->validate($k, $v) ) {
unset($exif[$k]);
}
}
foreach($exif as $k => $v) {
if ( !$this->exif->validate($k, $v) ) {
- wfDebug( "Image::retrieveExifData: '$k' did not contain valid contents (contents: '$v')\n");
+ wfDebug( "Image::retrieveExifData: '$k' contained invalid data (type: '" . gettype($v) . "'; data: '$v')\n");
function getExifData () {
global $wgRequest;
function getExifData () {
global $wgRequest;
+ $purge = $wgRequest->getVal( 'action' ) == 'purge';
$ret = unserialize ( $this->metadata );
$ret = unserialize ( $this->metadata );
- if ( count( $ret) == 0 || $wgRequest->getVal( 'action' ) == 'purge' ) { # No EXIF data was stored for this image
- $this->updateExifData() ;
- $ret = unserialize ( $this->metadata ) ;
+ $oldver = isset( $ret['MEDIAWIKI_EXIF_VERSION'] ) ? $ret['MEDIAWIKI_EXIF_VERSION'] : 0;
+ $newver = $this->exif->version();
+
+ if ( !count( $ret ) || $purge || $oldver != $newver ) {
+ echo "old: $oldver; new: $newver\n";
+ echo "updating\n";
+ $this->updateExifData( $newver );
+ $ret = unserialize( $this->metadata );
+ if ( isset( $ret['MEDIAWIKI_EXIF_VERSION'] ) )
+ unset( $ret['MEDIAWIKI_EXIF_VERSION'] );
foreach($ret as $k => $v) {
$ret[$k] = $this->exif->format($k, $v);
}
foreach($ret as $k => $v) {
$ret[$k] = $this->exif->format($k, $v);
}
- function updateExifData () {
- global $wgShowEXIF ;
- if ( ! $wgShowEXIF ) return ;
- if ( false === $this->getImagePath() ) return ; # Not a local image
+ function updateExifData( $version ) {
+ global $wgShowEXIF;
+ $fname = 'Image:updateExifData';
- $fname = "Image:updateExifData" ;
+ if ( ! $wgShowEXIF || $this->getImagePath() === false ) # Not a local image
+ return;
# Get EXIF data from image
# Get EXIF data from image
- $exif = $this->retrieveExifData () ;
- $this->metadata = serialize ( $exif );
+ $exif = $this->retrieveExifData();
+ $exif['MEDIAWIKI_EXIF_VERSION'] = $version;
+ $this->metadata = serialize( $exif );
# Update EXIF data in database
$dbw =& wfGetDB( DB_MASTER );
# Update EXIF data in database
$dbw =& wfGetDB( DB_MASTER );